package com.book.controller;


import com.book.po.notice;
import com.book.po.s_n;
import com.book.po.student;
import com.book.service.noticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/notice")
public class noticeController {
    @Autowired
    private com.book.service.noticeService noticeService;

    @RequestMapping("/notice_select")
    public String book_select(RedirectAttributes  model,String sid, HttpSession session){
        student student =(student) session.getAttribute("student");
        sid = student.getId();
        List<notice> notices = noticeService.notice_select(sid);
        if (notices.size()>=1){
            model.addFlashAttribute("notices",notices);
            model.addFlashAttribute("msg","");
            return "redirect:/user/noticemanage";
        }else {
            model.addFlashAttribute("msg","没有消息记录！");
            return "redirect:/user/noticemanage";
        }
    }

//    @RequestMapping("/book_insert")
//    public String book_insert(RedirectAttributes  model, Book book){
//        if (book!=null) {
//            book.setCurrentNum(book.getNum());
//        }
//        String msg = bookService.book_insert(book);
//
//        model.addFlashAttribute("msg",msg);
//        return "redirect:/manage/bookManage";
//    }
//
    @RequestMapping("/sign_update")
    public String show_detail(RedirectAttributes  model, s_n s_n){
        s_n.setSign("1");
        String msg = noticeService.sign_update(s_n);
        model.addFlashAttribute("msg",msg);
        return "redirect:/user/noticemanage";
    }
    @RequestMapping("/show_detail")
    public String sign_update(RedirectAttributes  model, s_n s_n,String content){
        s_n.setSign("1");
        noticeService.sign_update(s_n);
        model.addFlashAttribute("msg",content);
        return "redirect:/user/noticemanage";
    }
//
//    @RequestMapping("/book_delete")
//    public String book_delete(RedirectAttributes  model, Integer bookId){
//        String msg = bookService.book_delete(bookId);
//        model.addFlashAttribute("msg",msg);
//        return "redirect:/manage/bookManage";
//    }
}
